package com.xxdh.service.impl;

import com.xxdh.domain.po.Course;
import com.xxdh.domain.po.StudentCourseRelation;
import com.xxdh.mapper.StudentCourseRelationMapper;
import com.xxdh.service.ICourseService;
import com.xxdh.service.IStudentCourseRelationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * <p>
 * 学生课程表 服务实现类
 * </p>
 *
 * @author zwg
 * @since 2024-10-16
 */
@Service
@RequiredArgsConstructor
public class StudentCourseRelationServiceImpl extends ServiceImpl<StudentCourseRelationMapper, StudentCourseRelation> implements IStudentCourseRelationService {
    private final StudentCourseRelationMapper studentCourseRelationMapper;

    /**
     * 根据课程id列表获取学生id列表
     * @param courseIds
     * @return
     */
    @Override
    public List<Long> getStudentIdListByTeacherId(List<Long> courseIds) {
        // 根据课程ID列表查询学生ID列表
        List<Long> studentIds = studentCourseRelationMapper.selectStudentIdListByCourseIdList(courseIds);
        return studentIds;
    }

    @Override
    public List<Long> getStudentIdListByCourseId(Long courseId) {
        List<StudentCourseRelation> studentCourseRelations = lambdaQuery().eq(StudentCourseRelation::getCourseId, courseId).list();
        List<Long> studentIds = studentCourseRelations.stream().map(StudentCourseRelation::getStudentId).collect(Collectors.toList());
        return studentIds;
    }
}
